// pages/myinformation/myinformation.js
const app = getApp()

Page({

  /**
   * 页面的初始数据
   */
  data: {
    step:1,
    pageCount:1,
    bookid1:"",
    bookid2:"",
    bookid3:"",
    bookid4:"",
    bookid5:"",
  },

  prevStep:function(e){
    this.setData({
      step:this.data.step-1
    })
    this.onShow();
  },
  nextStep:function(e){
    this.setData({
      step:this.data.step+1
    })
    this.onShow();
  },
  button1:function(e){
    console.log("bookid1=",this.data.bookid1)
    wx.navigateTo({
      url: '/pages/detail/detail?id='+this.data.bookid1
    })
    return
  },
  
  button2:function(e){
    console.log("bookid2=",this.data.bookid2)
    wx.navigateTo({
      url: '/pages/detail/detail?id='+this.data.bookid2
    })
    return
  },
  
  button3:function(e){
    console.log("bookid3=",this.data.bookid3)
    wx.navigateTo({
      url: '/pages/detail/detail?id='+this.data.bookid3
    })
    return
  },
  
  button4:function(e){
    console.log("bookid4=",this.data.bookid4)
    wx.navigateTo({
      url: '/pages/detail/detail?id='+this.data.bookid4
    })
    return
  },
  
  button5:function(e){
    console.log("bookid5=",this.data.bookid5)
    wx.navigateTo({
      url: '/pages/detail/detail?id='+this.data.bookid5
    })
    return
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    console.log("openid:",app.globalData.openid)
    console.log("step:",this.data.step)
    wx.cloud.callFunction({
      name: 'get_books_os',
      data: {
        openid:app.globalData.openid,
        query:{
          pageIndex:this.data.step,
          pageSize:5
        }
      },
        success: res => {
          console.log("return data",res.result.data)
          console.log("return pageCount",res.result.pageCount)
          this.setData({
            pageCount:res.result.pageCount,

            bookid1: res.result.data[0]._id,
            name1: res.result.data[0].name,
            price1: res.result.data[0].price,

            bookid2: res.result.data[1]._id,
            name2: res.result.data[1].name,
            price2: res.result.data[1].price,

            bookid3: res.result.data[2]._id,
            name3: res.result.data[2].name,
            price3: res.result.data[2].price,

            bookid4: res.result.data[3]._id,
            name4: res.result.data[3].name,
            price4: res.result.data[3].price,

            bookid5: res.result.data[4]._id,
            name5: res.result.data[4].name,
            price5: res.result.data[4].price,
          })
        },
        fail: err => {
          console.error('[云函数] [login] 调用失败', err)
        }
      })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})